package com.caocaog.market.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.caocaog.market.entity.Information;
import com.caocaog.market.entity.InformationDetail;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.type.JdbcType;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecg.common.handler.ListToStringHandler;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Getter
@Setter
public class InformationVO implements Serializable {
    private static final long serialVersionUID = 1L;

    // Base
    private String id;
    private String createBy;
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
    private Date createTime;
    private String updateBy;
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
    private Date updateTime;
    private Integer lockVersion;
    private Integer delFlag;

    // Information
    @Dict(dictTable = "sys_category", dicText = "name", dicCode = "code")
    private String parentType;
    @Dict(dictTable = "sys_category", dicText = "name", dicCode = "code")
    private String childrenType;
    private String name;
    @Dict(dictTable = "mk_site_basic", dicText = "name", dicCode = "id")
    private String siteId;
    @Dict(dicCode = "information_status")
    private Integer status;
    @Dict(dicCode = "information_upShelf")
    private Integer upShelf;
    private String code;
    private Integer readQty;
    private Integer replyQty;
    private String phone;

    // InformationDetail
    private String content;
    private List<String> images;

    // 转换为Information
    public Information toInformation() {
        Information information = new Information();
        information.setId(this.id);
        information.setCreateBy(this.createBy);
        information.setCreateTime(this.createTime);
        information.setUpdateBy(this.updateBy);
        information.setUpdateTime(this.updateTime);
        information.setLockVersion(this.lockVersion);
        information.setDelFlag(this.delFlag);
        information.setParentType(this.parentType);
        information.setChildrenType(this.childrenType);
        information.setName(this.name);
        information.setSiteId(this.siteId);
        information.setStatus(this.status);
        information.setUpShelf(this.upShelf);
        information.setCode(this.code);
        information.setReadQty(this.readQty);
        information.setReplyQty(this.replyQty);
        information.setPhone(this.phone);
        return information;
    }

    // 转换为InformationDetail
    public InformationDetail toInformationDetail() {
        InformationDetail informationDetail = new InformationDetail();
        informationDetail.setId(this.id);
        informationDetail.setContent(this.content);
        informationDetail.setImages(StringUtils.join(this.images, ","));
        return informationDetail;
    }

    // Information传入VO
    public InformationVO setInformation(Information information) {
        this.id = information.getId();
        this.createBy = information.getCreateBy();
        this.createTime = information.getCreateTime();
        this.updateBy = information.getUpdateBy();
        this.updateTime = information.getUpdateTime();
        this.lockVersion = information.getLockVersion();
        this.delFlag = information.getDelFlag();
        this.parentType = information.getParentType();
        this.childrenType = information.getChildrenType();
        this.name = information.getName();
        this.siteId = information.getSiteId();
        this.status = information.getStatus();
        this.upShelf = information.getUpShelf();
        this.code = information.getCode();
        this.readQty = information.getReadQty();
        this.replyQty = information.getReplyQty();
        this.phone = information.getPhone();
        return this;
    }

    // InformationDetail传入VO
    public InformationVO setInformationDetail(InformationDetail informationDetail) {
        this.id = informationDetail.getId();
        this.content = informationDetail.getContent();
        this.images = Arrays.asList(informationDetail.getImages().split(","));
        return this;
    }

}
